Storage Calculation for VARCHAR(255) vs CHAR(255) with utf8mb4
MySQL calculates storage for VARCHAR and CHAR differently, especially when using utf8mb4, which requires up to 4 bytes per character.
utf8mb4 uses up to 4 bytes per character.
Maximum possible data storage = 255 × 4 = 1020 bytes.
VARCHAR also requires 1 or 2 bytes for length storage.
Because 1020 > 255, VARCHAR(255) uses 2 bytes for length.
Total max storage = 1020 bytes + 2 bytes = 1022 bytes.
CHAR is fixed-length and always allocates full size.
Each character may need up to 4 bytes in utf8mb4.
Total storage = 255 × 4 = 1020 bytes (always reserved).
CHAR adds 1 byte for padding metadata internally.
CHAR wastes more space but is faster for fixed-length lookups.
VARCHAR stores variable-length data with 1–2 bytes overhead; CHAR always stores fixed-length.
VARCHAR(255) max size = 1022 bytes; CHAR(255) always uses 1020 bytes.
CHAR is less space-efficient with utf8mb4 because every row reserves the full 255 characters × 4 bytes.
VARCHAR is preferred for variable-length text; CHAR is ideal for fixed-size data like hashes or codes.